# Replication files for JOP article:
# Beyond the glass ceiling, more `housework'? 
# Womens' work assignment, performance and influence in political institutions


# By Louisa Boulaziz 


# Description of script: This script includes all the alternative analysis 
# for the assignment models as well as descriptive statistics. 
# As such, this script includes all figures and tables from Appendix A

#----------------------------------------------------------------------
# PACKAGES

library(tidyverse)
library(gridExtra)
library(stargazer)
library(mclogit)
library(survival)
library(survminer)
library(coxed)
library(eha)
library(MASS)
library(lmtest)
library(multiwayvcov)
library(marginaleffects)


#----------------------------------------------------------------------
# REPLICATING TABLE 1 FROM APPENDIX (APPENDIX A1)

# Loading in data
load("data-cs.rdata")

# Estimating models 
mod_ms <- clogit(is_judge_rapporteur ~ 
                   # gender
                   is_female + 
                   # judge level at case variables 
                   years_in_court_when_case_decided+
                   +age_judge_when_case_decided+ decisions_per_year+
                   # background
                   former_gc_judge + former_ag + was_judge + was_academic +
                   was_civil_servant 
                 + was_lawyer + was_politician + member_state
                 # strata
                 + strata(iuropa_decision_id),
                 # data
                 data = data)

mod <- clogit(is_judge_rapporteur ~ 
                # gender
                is_female + 
                # judge level at case variables 
                years_in_court_when_case_decided+
                +age_judge_when_case_decided+ decisions_per_year+
                # background
                former_gc_judge + former_ag + was_judge + was_academic +
                was_civil_servant 
              + was_lawyer + was_politician #+ member_state
              # strata
              + strata(iuropa_decision_id),
              # data
              data = data)

## Choice-set models with interaction effect 


mod_salience_ms <- mclogit(cbind(is_judge_rapporteur, set) ~ 
                             
                             # gender
                             is_female* salience+
                             
                             # judge level at case variables 
                             years_in_court_when_case_decided + age_judge_when_case_decided +
                             decisions_per_year+
                             # background
                             former_gc_judge + former_ag + was_judge + was_academic +
                             was_civil_servant + was_lawyer + was_politician + member_state,
                           
                           data = data)


mod_salience <- mclogit(cbind(is_judge_rapporteur, set) ~ 
                          
                          # gender
                          is_female* salience+
                          
                          # judge level at case variables 
                          years_in_court_when_case_decided + age_judge_when_case_decided +
                          decisions_per_year+
                          # background
                          former_gc_judge + former_ag + was_judge + was_academic +
                          was_civil_servant + was_lawyer + was_politician, # + member_state,
                        
                        data = data)



# Table to reproduce the results 

stargazer(mod, mod_ms, mod_salience, mod_salience_ms, type = "text", omit= c("member_state"), single.row = T,
          dep.var.caption= "Likelihood of case assignment",
          dep.var.labels = "",
          omit.stat = c("rsq", "ll", "logrank", "wald", "max.rsq", "lr"),
          # dep.var.labels = c("(1) All votes          (2) Split votes"),
          # model.names = TRUE,
          # model.numbers = F,
          covariate.labels = c("Female judge", 
                               "Case importance", 
                               "Years in court", 
                               "Age", 
                               "Work load", 
                               "Former GC judge", 
                               "Former AG", 
                               "Former judge", 
                               "Former academic", 
                               "Former civil servant", 
                               "Former lawyer", 
                               "Former politician", 
                               "Female x Case importance"
          ),
          add.lines=list(c("Member state fixed effects","NO", "YES", "NO", "YES")), 
          header = FALSE, 
          font.size = "scriptsize", 
          title = "Effect of gender and case importance on case assignments in the CJEU")


#----------------------------------------------------------------------
# REPLICATING FIGURE 1 AND 2 FROM APPENDIX 


case_importance <- data %>% 
  dplyr::select(iuropa_decision_id, salience_measure, salience, salience_1)


case_importance <- distinct(case_importance)

p1 <- case_importance %>% 
  group_by(salience_measure) %>% 
  count() %>% 
  ggplot(aes(salience_measure, n)) + 
  geom_col() + 
  coord_flip() + 
  theme_classic() + 
  ylab("Number of cases") + 
  xlab("Number of judges") + 
  scale_x_continuous(breaks = c(1:27)) + 
  ggtitle("Number of judges on cases")


plot2 <- case_importance %>% 
  group_by(salience) %>% 
  count() %>% 
  ggplot(aes(as.factor(salience), n)) + 
  geom_col() + 
  coord_flip() + 
  theme_classic() + 
  ylab("Number of cases") + 
  xlab("") + 
  scale_x_discrete(labels= c("0" = "Ordinary case", "1" = "Important case")) + 
  ggtitle("Case importance distribution across
          binary measure of case importance")

plot3 <- case_importance %>% 
  group_by(salience_1) %>% 
  count() %>% 
  ggplot(aes(as.factor(salience_1), n)) + 
  geom_col() + 
  coord_flip() + 
  theme_classic() + 
  ylab("Number of cases") + 
  xlab("Case importance") + 
  scale_x_discrete(labels = c("0" = "3 judges", "1" = "5 judges", "2" = "> 5 judges")) + 
  ggtitle("Case importance distribution across
          alternative measure of case importance")

p1
plot2
plot3

#----------------------------------------------------------------------
# REPLICATING TABLE 2 FROM THE APPENDIX (APPENDIX A2) 

mod_salience1 <- mclogit(cbind(is_judge_rapporteur, set) ~ 
                           
                           # gender
                           is_female* as.factor(salience_1)+
                           
                           # judge level at case variables 
                           years_in_court_when_case_decided + age_judge_when_case_decided +
                           decisions_per_year+
                           # background
                           former_gc_judge + former_ag + was_judge + was_academic +
                           was_civil_servant + was_lawyer + was_politician #+ member_state
                         ,
                         
                         data = data)


mod_salience2 <- mclogit(cbind(is_judge_rapporteur, set) ~ 
                           
                           # gender
                           is_female* as.factor(salience_1)+
                           
                           # judge level at case variables 
                           years_in_court_when_case_decided + age_judge_when_case_decided +
                           decisions_per_year+
                           # background
                           former_gc_judge + former_ag + was_judge + was_academic +
                           was_civil_servant + was_lawyer + was_politician + member_state
                         ,
                         
                         data = data)


# Making the table 

stargazer(mod_salience1, mod_salience2, type = "text", omit= c("member_state"), single.row = T,
          dep.var.caption= "Likelihood of case assignment",
          dep.var.labels = "",
          omit.stat = c("rsq", "ll", "logrank", "wald", "max.rsq", "lr"),
          # dep.var.labels = c("(1) All votes          (2) Split votes"),
          # model.names = TRUE,
          # model.numbers = F,
          covariate.labels = c("Female judge", 
                               "Case importance 1",
                               "Case importance 2",
                               "Years in court", 
                               "Age", 
                               "Work load", 
                               "Former GC judge", 
                               "Former AG", 
                               "Former judge", 
                               "Former academic", 
                               "Former civil servant", 
                               "Former lawyer", 
                               "Former politician",
                               "Female judge x case importance 1", 
                               "Female judge x case importance 2"),
          add.lines=list(c("Member state fixed effects","NO", "YES")), 
          header = FALSE, 
          font.size = "scriptsize", 
          title = "Effect of gender and case importance on case assignments in the CJEU. Note: Models estimated with an alternative measure of case importance.")


#----------------------------------------------------------------------
# REPLICATING TABLE 3 FROM THE APPENDIX (APPENDIX A3)

mod_ms <- clogit(is_judge_rapporteur ~ 
                   # gender
                   is_female * years_in_court_when_case_decided+
                   +age_judge_when_case_decided+ decisions_per_year+
                   # background
                   former_gc_judge + former_ag + was_judge + was_academic +
                   was_civil_servant 
                 + was_lawyer + was_politician + member_state
                 # strata
                 + strata(iuropa_decision_id),
                 # data
                 data = data)

mod_salience_ms <- mclogit(cbind(is_judge_rapporteur, set) ~ 
                             
                             # gender
                             is_female*years_in_court_when_case_decided* salience+
                             
                             # judge level at case variables 
                             + age_judge_when_case_decided +
                             decisions_per_year+
                             # background
                             former_gc_judge + former_ag + was_judge + was_academic +
                             was_civil_servant + was_lawyer + was_politician + member_state,
                           
                           data = data)

mod_salience_time <- mclogit(cbind(is_judge_rapporteur, set) ~ 
                               
                               # gender
                               is_female +years_in_court_when_case_decided* salience+
                               
                               # judge level at case variables 
                               + age_judge_when_case_decided +
                               decisions_per_year+
                               # background
                               former_gc_judge + former_ag + was_judge + was_academic +
                               was_civil_servant + was_lawyer + was_politician + member_state,
                             
                             data = data)

# Making table 

stargazer(mod_ms, mod_salience_ms, mod_salience_time, type = "text", omit = c("member_state"), 
          single.row = T,
          dep.var.caption= "Likelihood of case assignment",
          dep.var.labels = "",
          omit.stat = c("rsq", "ll", "logrank", "wald", "max.rsq", "lr"),
          # dep.var.labels = c("(1) All votes          (2) Split votes"),
          # model.names = TRUE,
          # model.numbers = F,
          covariate.labels = c("Female judge", 
                               "Years in court", 
                               "Case importance", 
                               "Age", 
                               "Work load", 
                               "Former GC judge", 
                               "Former AG", 
                               "Former judge", 
                               "Former academic", 
                               "Former civil servant", 
                               "Former lawyer", 
                               "Former politician",
                               "Female judge x years in court", 
                               "Female judge x Case importance", 
                               "Years in court x Case importance",
                               "Female judge x Years in court x Case importance"
          ),
          add.lines=list(c("Member state fixed effects", "YES", "YES", "YES")), 
          header = FALSE, 
          font.size = "scriptsize", 
          title = "Effect of gender, years in court and case importance on case assignments in the CJEU")


#----------------------------------------------------------------------
# REPLICATING TABLE 4 FROM THE APPENDIX (APPENDIX A4)


mod_ms <- clogit(is_judge_rapporteur ~ 
                   # gender
                   is_female* age_judge_when_case_decided +
                   # judge level at case variables 
                   years_in_court_when_case_decided
                 + decisions_per_year+
                   # background
                   former_gc_judge + former_ag + was_judge + was_academic +
                   was_civil_servant 
                 + was_lawyer + was_politician + member_state
                 # strata
                 + strata(iuropa_decision_id),
                 # data
                 data = data)


mod_salience_ms <- mclogit(cbind(is_judge_rapporteur, set) ~ 
                             
                             # gender
                             is_female* age_judge_when_case_decided*salience+
                             
                             # judge level at case variables 
                             years_in_court_when_case_decided  +
                             decisions_per_year+
                             # background
                             former_gc_judge + former_ag + was_judge + was_academic +
                             was_civil_servant + was_lawyer + was_politician + member_state,
                           
                           data = data)

mod_salience_age <- mclogit(cbind(is_judge_rapporteur, set) ~ 
                              
                              # gender
                              is_female + age_judge_when_case_decided*salience+
                              
                              # judge level at case variables 
                              years_in_court_when_case_decided  +
                              decisions_per_year+
                              # background
                              former_gc_judge + former_ag + was_judge + was_academic +
                              was_civil_servant + was_lawyer + was_politician + member_state,
                            
                            data = data)


# Making the table 

stargazer( mod_ms,  mod_salience_ms, mod_salience_age, type = "text", omit= c("member_state"), single.row = T,
           dep.var.caption= "Likelihood of case assignment",
           dep.var.labels = "",
           omit.stat = c("rsq", "ll", "logrank", "wald", "max.rsq", "lr"),
           # dep.var.labels = c("(1) All votes          (2) Split votes"),
           # model.names = TRUE,
           # model.numbers = F,
           covariate.labels = c("Female judge", 
                                "Age", 
                                "Case importance", 
                                "Years in court", 
                                "Work load", 
                                "Former GC judge", 
                                "Former AG", 
                                "Former judge", 
                                "Former academic", 
                                "Former civil servant", 
                                "Former lawyer", 
                                "Former politician", 
                                "Female judge x Age",
                                "Female judge x Case importance", 
                                "Age x Case importance", 
                                "Female judge x Age x Case importance"
           ),
           add.lines=list(c("Member state fixed effects","NO", "YES", "NO", "YES")), 
           header = FALSE, 
           font.size = "scriptsize", 
           title = "Effect of gender, age and case importance on case assignments in the CJEU")


#----------------------------------------------------------------------
# REPLICATING FIGURES 3-7 FROM THE APPENDIX (APPENDIX A5)

load("time_data.Rdata") # Case level data


# Descriptive statistics

mean(time_data$duration_days)

# Creating salience 

### Binary
time_data$salience <- ifelse(time_data$count_judges > 5, 1, 0)

# Creating policy-areas

time_data$test_policy_area <- gsub(pattern = ",.*", 
                                   replacement = "", 
                                   time_data$list_policy_areas)

# Creating factor gender 

time_data$gender <- ifelse(time_data$is_female == 1, "Female judge", "Male judge")

# Creating year variable for the time_data 

time_data$decision_year <- gsub(pattern = "-.*", 
                                replacement = "", 
                                time_data$decision_date)

# Making distribution plots 

d <- time_data %>%
  group_by(test_policy_area, salience) %>%
  count() %>%
  rename(total = n)

d1 <- time_data %>%
  group_by(test_policy_area) %>%
  count() %>%
  rename(case_area_count = n)

d <- merge(d, d1, by = "test_policy_area")

d$percentage <- d$total/d$case_area_count*100

case_importance<-  d %>%
  filter(test_policy_area != "none") %>%
  ggplot(aes(test_policy_area, percentage, fill = as.factor(salience))) + 
  geom_col() + 
  coord_flip()+ 
  theme_bw() + 
  labs(fill = "Case importance") + 
  ggtitle("Overall case salience") +
  xlab("Policy area") + 
  ylab("Percentage of case") + 
  theme_classic()

case_importance

# Salient cases 
d <- time_data %>%
  filter(count_judges > 5) %>%
  group_by(test_policy_area) %>%
  count() %>% 
  rename(total = n)

d1 <- time_data %>%
  filter(count_judges > 5) %>%
  group_by(test_policy_area, gender) %>%
  count() %>%
  rename(case_gender = n)

d <- merge(d, d1, by = "test_policy_area")

d$percentage <- d$case_gender/d$total*100

salient <- d %>%
  filter(test_policy_area != "none") %>%
  ggplot(aes(test_policy_area, percentage, fill = gender)) + 
  geom_col() + 
  coord_flip()+ 
  theme_bw() + 
  labs(fill = "Gender") + 
  ggtitle("Salient cases") +
  xlab("Policy area") + 
  ylab("Percentage of case")+
  theme_classic()

salient


# Non-salient cases 
d <- time_data %>%
  filter(count_judges <= 5) %>%
  group_by(test_policy_area) %>%
  count() %>% 
  rename(total = n)

d1 <- time_data %>%
  filter(count_judges <= 5) %>%
  group_by(test_policy_area, gender) %>%
  count() %>%
  rename(case_gender = n)

d <- merge(d, d1, by = "test_policy_area")

d$percentage <- d$case_gender/d$total*100

non_salient <- d %>%
  filter(test_policy_area != "none") %>%
  ggplot(aes(test_policy_area, percentage, fill = gender)) + 
  geom_col() + 
  coord_flip()+ 
  theme_bw() + 
  labs(fill = "Gender") + 
  ggtitle("Non-salient cases") +
  xlab("Policy area") + 
  ylab("Percentage of case")+ 
  theme_classic()

non_salient

# All cases 

d <- time_data %>%
  #filter(count_judges > 5) %>%
  group_by(test_policy_area) %>%
  count() %>% 
  rename(total = n)

d1 <- time_data %>%
  #filter(count_judges > 5) %>%
  group_by(test_policy_area, gender) %>%
  count() %>%
  rename(case_gender = n)

d <- merge(d, d1, by = "test_policy_area")

d$percentage <- d$case_gender/d$total*100

all_cases <- d %>%
  filter(test_policy_area != "none") %>%
  ggplot(aes(test_policy_area, percentage, fill = gender)) + 
  geom_col() + 
  coord_flip()+ 
  theme_bw() + 
  labs(fill = "Gender") + 
  ggtitle("All cases") +
  xlab("Policy area") + 
  ylab("Percentage of case")+
  theme_classic()

all_cases

# Percentage of cases within policy areas 
## All cases
d <- time_data %>%
  group_by(test_policy_area) %>%
  count()

d$total <- 5303

d$percentage <- d$n/d$total*100

percentage_policy <- d %>%
  filter(test_policy_area != "none") %>%
  ggplot(aes(reorder(test_policy_area, -percentage), percentage)) + 
  geom_col() + 
  coord_flip()+ 
  theme_bw() + 
  labs(fill = "Case importance") + 
  ggtitle("Policy area of cases") +
  xlab("") + 
  ylab("Percentage of cases between 2004-2022")+ 
  theme_classic()

percentage_policy


#----------------------------------------------------------------------
# ESTIMATING POLICY AREA MODELS (ORGINALLY NOT IN THE APPENDIX, BUT HAVE BEEN ADDED)
# NOW MARKED AS TABLE 5
# Making policy area models 

mod_policy_area_ms <- mclogit(cbind(is_judge_rapporteur, set) ~ 
                                
                                # gender
                                is_female*test_policy_areas+
                                
                                # judge level at case variables 
                                years_in_court_when_case_decided + age_judge_when_case_decided +
                                decisions_per_year+
                                # background
                                former_gc_judge + former_ag + was_judge + was_academic +
                                was_civil_servant + was_lawyer + was_politician + member_state,
                              
                              data = data)


mod_policy_area_salience <- mclogit(cbind(is_judge_rapporteur, set) ~ 
                                      
                                      # gender
                                      is_female*test_policy_areas*salience+
                                      
                                      # judge level at case variables 
                                      years_in_court_when_case_decided + age_judge_when_case_decided +
                                      decisions_per_year+
                                      # background
                                      former_gc_judge + former_ag + was_judge + was_academic +
                                      was_civil_servant + was_lawyer + was_politician + member_state,
                                    
                                    data = data)


# Results (this table was not included in the appendix, but has been included now)

stargazer(mod_policy_area_ms, mod_policy_area_salience, type = "text", omit = c("member_state", "test_policy_areas"),
          single.row = T,
          dep.var.caption= "Likelihood of case assignment",
          dep.var.labels = "",
          omit.stat = c("rsq", "ll", "logrank", "wald", "max.rsq", "lr"),
          covariate.labels = c("Female judge", 
                               "Case importance", 
                               "Years in court", 
                               "Age", 
                               "Work load", 
                               "Former GC judge", 
                               "Former AG", 
                               "Former judge", 
                               "Former academic", 
                               "Former civil servant", 
                               "Former lawyer", 
                               "Former politician", 
                               "Female judge x Case importance" 
          ),
          add.lines=list(c("Member state fixed effects", "YES", "YES"), 
                         c("Interaction Female judge x Policy ares", "YES", "NO"), 
                         c("Interaction Female judge x Policy area x Case importance", "NO", "YES")), 
          header = FALSE, 
          font.size = "scriptsize", 
          title = "Effect of gender and case importance on case assignments in the CJEU, including interaction effects on gender and policy area and gender, policy area and case importance")


#----------------------------------------------------------------------
# REPLICATING FIGURES 8-10 FROM THE APPENDIX (APPENDIX A6)


time_data1 <- time_data

time_data1$decision_type <- ifelse(time_data1$is_appeal == 1, "Appeal", 
                                   ifelse(time_data1$is_direct_action == 1, "Direct action", 
                                          ifelse(time_data1$is_preliminary_ruling == 1, "Preliminary ruling", 0)))

time_data1 <- time_data1 %>% 
  filter(decision_type != "0")


### Salient cases 
d <- time_data1 %>%
  filter(count_judges > 5) %>%
  group_by(decision_type) %>%
  count() %>% 
  rename(total = n)

d1 <- time_data1 %>%
  filter(count_judges > 5) %>%
  group_by(decision_type, gender) %>%
  count() %>%
  rename(case_gender = n)

d <- merge(d, d1, by = "decision_type")

d$percentage <- d$case_gender/d$total*100

salient <- d %>%
  #  filter(test_policy_area != "none") %>%
  ggplot(aes(decision_type, percentage, fill = gender)) + 
  geom_col() + 
  coord_flip()+ 
  theme_bw() + 
  labs(fill = "Gender") + 
  ggtitle("Salient cases across gender") +
  xlab("Type of procedure") + 
  ylab("Percentage of case")+
  theme_classic()

salient
###### Non-salient cases 
d <- time_data1 %>%
  filter(count_judges <= 5) %>%
  group_by(decision_type) %>%
  count() %>% 
  rename(total = n)

d1 <- time_data1 %>%
  filter(count_judges <= 5) %>%
  group_by(decision_type, gender) %>%
  count() %>%
  rename(case_gender = n)

d <- merge(d, d1, by = "decision_type")

d$percentage <- d$case_gender/d$total*100

non_salient <- d %>%
  #  filter(test_policy_area != "none") %>%
  ggplot(aes(decision_type, percentage, fill = gender)) + 
  geom_col() + 
  coord_flip()+ 
  theme_bw() + 
  labs(fill = "Gender") + 
  ggtitle("Non-salient cases across gender") +
  xlab("Type of procedure") + 
  ylab("Percentage of case")+ 
  theme_classic()

non_salient
############# All cases 

d <- time_data1 %>%
  #filter(count_judges > 5) %>%
  group_by(decision_type) %>%
  count() %>% 
  rename(total = n)

d1 <- time_data1 %>%
  #filter(count_judges > 5) %>%
  group_by(decision_type, gender) %>%
  count() %>%
  rename(case_gender = n)

d <- merge(d, d1, by = "decision_type")

d$percentage <- d$case_gender/d$total*100

all_cases <- d %>%
  #  filter(test_policy_area != "none") %>%
  ggplot(aes(decision_type, percentage, fill = gender)) + 
  geom_col() + 
  coord_flip()+ 
  theme_bw() + 
  labs(fill = "Gender") + 
  ggtitle("All cases across gender") +
  xlab("Type of procedure") + 
  ylab("Percentage of case")+
  theme_classic()

all_cases
############ Percentage of cases within policy areas 

############# All cases
d <- time_data1 %>%
  group_by(decision_type) %>%
  count()

d$total <- 5303

d$percentage <- d$n/d$total*100

percentage_policy <- d %>%
  #  filter(test_policy_area != "none") %>%
  ggplot(aes(reorder(decision_type, -percentage), percentage)) + 
  geom_col() + 
  coord_flip()+ 
  theme_bw() + 
  # labs(fill = "Case importance") + 
  ggtitle("Type of procedure") +
  xlab("") + 
  ylab("Percentage of cases between 2004-2022")+ 
  theme_classic()

percentage_policy


#----------------------------------------------------------------------
# REPLICATING TABLE 6 FROM THE APPENDIX (APPENDIX A6)

data$decision_type <- ifelse(data$is_appeal == 1, "Appeal", 
                             ifelse(data$is_direct_action == 1, "Direct action", 
                                    ifelse(data$is_preliminary_ruling == 1, "Preliminary ruling", 0)))

data <- data %>% 
  filter(decision_type != 0)

class(data$decision_type)
data$decision_type <- as.factor(data$decision_type)
data$decision_type <- relevel(data$decision_type, ref = "Preliminary ruling")

mod_case_ms <- mclogit(cbind(is_judge_rapporteur, set) ~ 
                         
                         # gender
                         is_female*decision_type+
                         
                         # judge level at case variables 
                         years_in_court_when_case_decided + age_judge_when_case_decided +
                         decisions_per_year+
                         # background
                         former_gc_judge + former_ag + was_judge + was_academic +
                         was_civil_servant + was_lawyer + was_politician + member_state,
                       
                       data = data)


mod_case_salience <- mclogit(cbind(is_judge_rapporteur, set) ~ 
                               
                               # gender
                               is_female*decision_type*salience+
                               
                               # judge level at case variables 
                               years_in_court_when_case_decided + age_judge_when_case_decided +
                               decisions_per_year+
                               # background
                               former_gc_judge + former_ag + was_judge + was_academic +
                               was_civil_servant + was_lawyer + was_politician + member_state,
                             
                             data = data)



# Making table 
stargazer(mod_case_ms, mod_case_salience, type = "text", omit = c("member_state"),
         single.row = T,
         dep.var.caption= "Likelihood of case assignment",
         dep.var.labels = "",
         omit.stat = c("rsq", "ll", "logrank", "wald", "max.rsq", "lr"),
         covariate.labels = c("Female judge", 
                              "Appeal", 
                              "Direct action",
                              "Case importance", 
                              "Years in court", 
                              "Age", 
                              "Work load", 
                              "Former GC judge", 
                              "Former AG", 
                              "Former judge", 
                              "Former academic", 
                              "Former civil servant", 
                              "Former lawyer", 
                              "Former politician", 
                              "Female judge x Appeals", 
                              "Female judge x Direct action", 
                              "Female judge x Salience", 
                              "Appeal x Salience", 
                              "Direct action x Salience", 
                              "Female judge x Appeal x Salience", 
                              "Female judge x Direct action x Salience"
         ),
         add.lines=list(c("Member state fixed effects", "YES", "YES")), 
         header = FALSE, 
         font.size = "scriptsize", 
         title = "Effect of gender and case importance on case assignments in the CJEU, including interaction effects on gender and procedure, procedure and case importance")


#----------------------------------------------------------------------
# REPLICATING TABLE 7 FROM THE APPENDIX (APPENDIX A7)

# OVERVIEW OF VARIABLES CHOICE-SET DATA

load("data-cs.Rdata")

to_show <- data %>% 
  dplyr::select(is_judge_rapporteur, is_female, salience, years_in_court_when_case_decided, age_judge_when_case_decided, decisions_per_year, former_gc_judge, former_ag, 
                was_judge, was_academic, was_civil_servant, was_lawyer, was_politician)

stargazer(to_show, type = "text", header = F, 
          covariate.labels = c("Case manager", 
                               "Gender", 
                               "Case importance", 
                               "Years in court (when case was decided)", 
                               "Age (when case was decided)", 
                               "Workload", 
                               "Former GC judge", 
                               "Former AG", 
                               "Former judge", 
                               "Former academic", 
                               "Former civil servant", 
                               "Former lawyer", 
                               "Former politician"), 
          title = "Distribution of continous and binary variables from the analysis. Variables at the choice-set level.")


#----------------------------------------------------------------------
# REPLICATING TABLE 8 FROM THE APPENDIX (APPENDIX A7)

load("judges_background.Rdata")
View(judges_background)
